<template>
  <layout>
    <div slot="body" style="font-size:150%">
      <div>bug list</div>
      <br>
    </div>
    <div slot="body">
      <el-tabs value="tab0">
        <el-tab-pane label="未回归" name="tab0">
          <h4>已 Done bug，回归完成，请打上 staging-test label</h4>
          <shopee-table :data="bugList1" style="width: 100%">
            <shopee-table-column
              label="缺陷" >
              <template slot-scope="{row}">
                  <div slot="reference">
                          <el-link target="_blank" :href="'https://jira.shopee.io/browse/'+row.key" type="primary">{{row.summary}}</el-link>
                  </div>
              </template>
            </shopee-table-column>
            <shopee-table-column prop="created" label="创建时间" :width="300"></shopee-table-column>
            <shopee-table-column prop="status" label="状态" :width="125"></shopee-table-column>

            <shopee-table-column label="操作" fixed="right" :width="200">
              <template slot-scope="props">
                <el-button size="small" @click="add_label(props.row.key)" type="primary" outline>标记为已回归</el-button>
              </template>
            </shopee-table-column>

          </shopee-table>
        </el-tab-pane>
        <el-tab-pane label="未关闭" name="tab1">
           <h4>历史bug 请先 close 后 clone 新的 bug 再 done，已确保不拉高 bug 平均解决时间</h4>
           <shopee-table :data="bugList2" style="width: 100%">
              <shopee-table-column
              label="缺陷" >
              <template slot-scope="{row}">
                  <div slot="reference">
                          <el-link target="_blank" :href="'https://jira.shopee.io/browse/'+row.key" type="primary">{{row.summary}}</el-link>
                  </div>
              </template>
            </shopee-table-column>
             <shopee-table-column prop="created" label="创建时间" :width="300"></shopee-table-column>
             <shopee-table-column prop="interval" label="距离天数" :width="80"></shopee-table-column>
            <shopee-table-column prop="status" label="状态" :width="125"></shopee-table-column>
          </shopee-table>
        </el-tab-pane>
      </el-tabs>
    </div>
  </layout>
</template>

<script>
  import Layout from "@/components/layout_tools/layout"
  import {api, getRequest,postRequest} from "@/api/commit";

  export default {
    name: "BugView",
    components: {
      Layout
    }, data() {
      return {
        bugList1: [],
        bugList2: [],
      }
    }, methods: {
      add_label(key){
        postRequest(api['add_label'], {key:key}).then((res) => {
          res = res.resultReturn
          this.init_data1()
        }, (error) => {
          console.info(error)
        })
      },
      init_data1() {
        getRequest(api['get_no_staging_bugs'], {}).then((res) => {
          res = res.resultReturn
          this.bugList1 = res.data
        }, (error) => {
          console.info(error)
        })
      },
      init_data2() {
        getRequest(api['get_no_end_bugs'], {}).then((res) => {
          res = res.resultReturn
          this.bugList2=res.data
        }, (error) => {
          console.info(error)
        })
      }
    }, mounted() {
      this.init_data1()
      this.init_data2()
    }
  }
</script>

<style scoped>

</style>
